package com.qf.goods.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.goods.entity.GoodsDetail;
import com.qf.goods.mapper.GoodsDetailMapper;
import com.qf.goods.service.GoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_goods
 * @Package com.qf.goods.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 13:26
 */

@Service
public class GoodsDetailServiceImpl implements GoodsDetailService {

    @Autowired
    private GoodsDetailMapper goodsDetailMapper;


    @Override
    @Transactional
    public void insert(GoodsDetail goodsDetail) {
        int i = goodsDetailMapper.insertSelective(goodsDetail);
        if (i != 1){
            throw new RuntimeException("购买失败");
        }
    }

    @Override
    public GoodsDetail findById(Integer id) {
        return goodsDetailMapper.selectById(id);
    }

    @Override
    public PageInfo<GoodsDetail> findBySortIdAndPage(Integer pageNum, Integer pageSize, Integer goodsSortId) {
        PageHelper.startPage(pageNum, pageSize);
        List<GoodsDetail> list = goodsDetailMapper.findBySortId(goodsSortId);
        PageInfo<GoodsDetail> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
